#ifndef EXPRESSION_H
#define EXPERSSION_H

#include "MyStack.h"

typedef MyStack<double, 100> DoubleStack;
typedef MyStack<char, 100> CharStack;

class Expression
{
private:
	char* m_pExpression;
	char* m_pNormalizedExpression;

	double m_Value;

public:
	Expression(const char* pExpression);
	~Expression();

private:
	Expression(const Expression & e) {}
	Expression& operator=(const Expression& e) {}

public:
	bool IsValid();
	double GetValue();
	const char* GetExpression();
	const char* GetNormalizedExpression();

private:
	bool CopyString(char*& pTarget, const char* pSource);

private:
	bool IsBlank(char c);
	bool IsOperation(char c);
	bool IsDigit(char c);
	double GetValueOfDigit(char c);
	double GetValueOfDigits(const char* str,int& cntDigits);
	int GetOperationPriority(char op);
	double PerformOperation(char op, double LeftArg, double RightArg);
	void NormalizeExpression();
	int GetNormalizedLength(const char* str);
	void CopyWithoutBlanks(char* pTarget, const char* pSource);
	bool IsValidExpression(const char* str);
	void ProcessStack(CharStack& OpStack, DoubleStack& ArgStack, int StopAtPriority);
	double Calculate(const char* str);
	double Evaluate();
};

#endif // EXPRESSION_H